import cgi
import datetime
import wsgiref.handlers
import os

from models import *
from services.loanservice import LoanService
from services.bookservice import BookService
from services.userservice import UserService
from services.bookownershipservice import BookOwnershipService

from google.appengine.ext.webapp import template
#from google.appengine.ext import db should never need to access the database directly. go through the services please
from google.appengine.api import users
from google.appengine.ext import webapp


class MainPageHandler(webapp.RequestHandler):
  def get(self):
	user = users.get_current_user()

	if user:
		template_values = {}
		path = os.path.join(os.path.dirname(__file__), 'templates/MainPage.html')
		self.response.out.write(template.render(path, template_values))
	else:
		self.redirect(users.create_login_url(self.request.uri))


application = webapp.WSGIApplication([
  ('/', MainPageHandler)
], debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()